package com.bicon.botu.mall.order.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.bicon.botu.core.base.common.Constants;
import com.bicon.botu.core.base.common.controller.BaseController;
import com.bicon.botu.core.base.common.entity.BaseResult;
import com.bicon.botu.mall.order.common.OrderConstans;
import com.bicon.botu.mall.order.entity.OrderAddress;
import com.bicon.botu.mall.order.entity.OrderDetailAddress;
import com.bicon.botu.mall.order.entity.OrderGoods;
import com.bicon.botu.mall.order.service.IOrderChildService;
import com.bicon.botu.mall.order.service.IOrderDetailAddressService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 订单地址 后端控制器
 * @author dsp
 * @date 2018/5/14 11:54
 */
@RestController
@RequestMapping("/V3.0.0/order-detail-address")
public class OrderDetailAddressControllerV3 extends BaseController {

    @Autowired
    private IOrderDetailAddressService iOrderDetailAddressService;

    @Autowired
    private IOrderChildService iOrderChildService;
    /**
     * 修改个人订单地址
     * @param orderAddress 订单地址对象
     * @return
     */
    @RequestMapping(value="update",method = RequestMethod.POST)
    public BaseResult update(OrderDetailAddress orderAddress){
        //个人订单参数校验
        if(orderAddress != null && StringUtils.isNotBlank(orderAddress.getId())){
            orderAddress.preUpdate();
            boolean result=iOrderDetailAddressService.updateById(orderAddress);
            if(result){
                List<OrderGoods> list = new OrderGoods().selectList(new EntityWrapper<OrderGoods>()
                        .eq("logic_delete", Constants.DEL_LOGIC_NORMAL).eq("id",orderAddress.getOrderGoodsId()));
                String remark = "修改订单收货信息";
                iOrderChildService.insertOrderRecord(getUserId(),list,remark);
                return sendResult200();
            }else{
                return sendResult(OrderConstans.RESPONSE_CODE_600,OrderConstans.RESPONSE_MESSAGE_600);
            }
        }else{
            return sendResult400();
        }
    }
}
